package com.goodsogood.union.auth.sync;

import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.github.kevinsawicki.http.HttpRequest;
import com.goodsogood.union.auth.conf.CommonConfiger;
import com.goodsogood.union.auth.conf.LogConfiger;
import com.goodsogood.union.auth.sync.util.MD5Util;

/**
 * 修改密码
 *
 * @author liuy
 */
@Component
public class PwdUpdateSynchronizer {
    private final Logger logger = LoggerFactory.getLogger(LogConfiger.SYS_DATA);
    private static final String editPwdUrl = CommonConfiger.getInstance().getHost() + "/union/syn/user/editPwd"; 
    public void execute(String userId, String pwd,String oldPwd) {
        try {
            String para = " {'userId':'" + userId + "','newPassword':'" + MD5Util.toMD5(pwd) + "','oldPassword':'"+oldPwd+"'}";
            Map<String, String> params = new HashMap<>();
            params.put("para", para);
            
            logger.info("sys.editPwd request is {}", params);
            
            String response = HttpRequest.post(
                    editPwdUrl,
                    params, 
                    true).body();
            
            logger.info("sys.editPwd response is {}", response);
        } catch (Exception e) {
            logger.error("sys.editPwd happen error , userId is {}, pwd is {}, error is ", userId, pwd, e);
        }

    }
}
